package bookmarkstest;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

import bookmarks.Bookmark;
import bookmarks.BookmarksIterator;

public class BookmarkIteratorTest {
        
        @Test
        public void testHasNextOnNullCollection(){
                
                BookmarksIterator it = new BookmarksIterator(null);             
                
                assertEquals("Has Next should false",false,it.hasNext());               
        
        }
        
        
        @Test(expected=IndexOutOfBoundsException.class)
        public void testIndexOutOfBoundsException(){
                
                BookmarksIterator it = new BookmarksIterator(null);     
                
                it.next();              
        
        }
        
        @Test(expected=IndexOutOfBoundsException.class)
        public void testIndexOutOfBoundsException2(){
                
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                Bookmark testBookmark3 = new Bookmark("facebook","facebook.com");
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                bookmarks.add(testBookmark3);
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                it.getElement(5);
        
        }
        
        @Test(expected=IndexOutOfBoundsException.class)
        public void testIndexOutOfBoundsException3(){
                
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                it.removeElement();
        
        }
        
        @Test
        public void testRemoveElement()
        {
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                Bookmark testBookmark3 = new Bookmark("facebook","facebook.com");
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                bookmarks.add(testBookmark3);
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                it.removeElement();
                assertEquals("Size should be 2",2,it.getSize());
                assertEquals("Current Position title should  be yahoo",1,it.getElement().getTitle());
                
                it.removeElement();
                it.removeElement();
                assertEquals("Size should be 0",0,it.getSize());
        }
        
        
        @Test
        public void testGetSize()
        {
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                assertEquals("Size should be 2",2,it.getSize());
                
        }
        
        @Test 
        public void testIteratorFirstPositionOnInit(){
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                Bookmark testBookmark3 = new Bookmark("facebook","facebook.com");
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                bookmarks.add(testBookmark3);
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                assertEquals("Current Position should 0",0,it.getCurrentItem());
        }
        
        @Test 
        public void testNextItem(){
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                Bookmark testBookmark3 = new Bookmark("facebook","facebook.com");
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                bookmarks.add(testBookmark3);
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                it.next();
                assertEquals("Current Position should 1",1,it.getCurrentItem());
                assertEquals("Current Position title should  be yahoo",1,it.getElement().getTitle());           
        
        }
        
        @Test 
        public void testHasNext(){
                ArrayList<Bookmark> bookmarks = new ArrayList<Bookmark>();              
                Bookmark testBookmark1 = new Bookmark("google","google.ro");
                Bookmark testBookmark2 = new Bookmark("yahoo","yahoo.com");
                Bookmark testBookmark3 = new Bookmark("facebook","facebook.com");
                
                bookmarks.add(testBookmark1);
                bookmarks.add(testBookmark2);
                bookmarks.add(testBookmark3);
                
                BookmarksIterator it = new BookmarksIterator(bookmarks);
                
                assertEquals("Has Next should true",true,it.hasNext());
                it.next();
                it.next();
                assertEquals("Has Next should false",false,it.hasNext());               
        
        }
        
        
        
        
        
        
        
}